package com.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

import com.dao.*;
import com.entity.Device;
import com.entity.Employee;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	@Override
	public Employee findEmployeeByID(int employeeID) {
		return (Employee) this.getHibernateTemplate().get(Employee.class, employeeID);
	}

	@Override
	public List<Employee> findAllEmployee() {
		List list=(List<Employee>)this.getHibernateTemplate().find("from Employee");
        return list;
	}

	@Override
	public boolean addEmployee(Employee employee) {
		try{
            this.getHibernateTemplate().clear();
            this.getHibernateTemplate().save(employee);
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
            return false;
        }
	}

	@Override
	public boolean updateEmployee(Employee employee) {
		try{
            this.getHibernateTemplate().clear();
            this.getHibernateTemplate().update(employee);
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
            return false;
        }
	}

	@Override
	public boolean deleteEmployee(Employee employee) {
		try{
            this.getHibernateTemplate().clear();
            this.getHibernateTemplate().delete(employee);
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
            return false;
        }
	}
	
	@Override
	public List<Employee> findUserByUserNameAndPasswoed(String username,String password){
		String hql="from Employee e where e.employeeName = '"+ username +"' and e.password = '"+ password +"'";
		return (List<Employee>) this.getHibernateTemplate().find(hql);
	}

}
